package com.hellomeng.basedata;

public class Variable {

    //变量定义
    public static void identifier(){
        int age;    //1.变量的声明
        age = 100;  //2.变量的初始化
        int myAge = 200;    //声明的同时进行初始化
        System.out.println("age="+age);
        System.out.println("myAge="+myAge);
    }

    //char类型定义
    public static void charTest(){
        char a = 'a';       //a
        //char b = 'ab';    //错
        char c = '\t';      //转义字符
        char d = '好';      //好
        char e = '\u2392';  //⎒
        char f = 222;       //Þ
        System.out.println(e);
        System.out.println(f);
    }

    //基本类型转换
    public static void change(){
        short a = 100;
        short b = 1;
        //short c = a+b; 错，a+b会自动提升为int
        int c = a+b;
        long d = a+b;

        double d1 = 12.9;
        int i1= (int)d1;    //12

        int i2 = 128;
        byte b1 = (byte)i2;     //-128 ,溢出
        System.out.println(b1);
    }


    public static void main(String[] args) {
        identifier();
        charTest();
        change();
    }
}
